package com.example.bijiabao.controller;


import com.example.bijiabao.utils.Result;
import com.example.bijiabao.entity.book;
import com.example.bijiabao.entity.bookPlatform;
import com.example.bijiabao.entity.user;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.bijiabao.services.spbookServices;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("spbook")
public class spbookController {
    @Autowired
    private spbookServices spbookServices;

    //连接book,platform,通过ISBN查询
    @GetMapping("/ISBN/list")
    public Result findAllBookByISBN(@RequestParam("ISBN") String ISBN){
        Result result = new Result();
        List<bookPlatform> list = null;
        list = spbookServices.findAllBookByISBN(ISBN);
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(list);
        return result;
    }

    //详情页最便宜商品
    @GetMapping("/ISBN/book")
    public Result findBookByISBN(@RequestParam("ISBN") String ISBN){
        Result result = new Result();
        bookPlatform lists = null;
        lists = spbookServices.findBookByISBN(ISBN);
        result.setCode(200);
        result.setMessage("生成成功");
        result.setObject(lists);
        return result;
    }

    //相同作者的书
    @GetMapping("/writer")
    public Result findBookByWriter(@RequestParam("writer") String writer){
        Result result = new Result();
        List<book> lists = null;
        lists = spbookServices.findBookByWrietr(writer);
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(lists);
        return result;
    }

    //
    @GetMapping("/sp/userName")
    public Result selectbyUserName(@RequestParam("userName") String userName){
        Result result = new Result();
        user lists = null;
        lists = spbookServices.selectbyUserName(userName);
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(lists);
        return result;
    }
}
